<template>
  <div class="login">
    <div class="box">
      <div class="logo f-w-b" style="font-size:18px">
        <!-- <img src="/static/images/logo.png" alt /> -->
        信息咨询服务系统
      </div>
      <div class="prompt">请输入您的账号、密码进入后台</div>
      <div class="form">
        <div class="note">账号 :</div>
        <div class="input">
          <el-input placeholder="请输入账号" v-model="username"></el-input>
        </div>
        <div class="note">密码 :</div>
        <div class="input">
          <el-input
            placeholder="请输入密码"
            v-model="password"
            type="password"
            @keyup.enter.native="login"
          ></el-input>
        </div>
        <div class="auto">
          <el-checkbox v-model="check">7天内自动登录</el-checkbox>
        </div>
        <el-button type="primary" class="submit" @click="login">登 录</el-button>
      </div>
    </div>
    <div class="copyright">
      2021 by 金航软件
      <a href="http://beian.miit.gov.cn/" style="color:#fff" class="ml-10">浙ICP备2020035303号-1</a>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      check: false
    };
  },
  methods: {
    login() {
      // 验证
      if (!this.username) {
        this.$message({
          type: "warning",
          message: "用户名不能为空"
        });
        return;
      }
      if (!this.password) {
        this.$message({
          type: "warning",
          message: "密码不能为空"
        });
        return;
      }
      // 登录验证
      var data = {
        username: this.username,
        password: this.password
      };
      this.axios.post("/admin/Index/login", data).then(response => {
        if (response.data.state) {
          var data = response.data;
          //  设置Cookie 并且一天过期
          this.Cookie.set("username", this.username, {
            expires: this.check ? 7 : 1
          });
          this.$store.state.user = data.user;
          this.$message({
            message: "欢迎 " + data.user.username + "  登录成功 !",
            type: "success",
            duration: 2000
          });
          this.$router.replace("/");
        } else {
          this.$message.error(response.data.info);
        }
      });
    }
  }
};
</script>
<style scoped>
.login {
  position: relative;
  height: 100vh;
  background-color: #409eff;
  background-image: url("/static/images/bg-pattern.png");
  background-size: cover;
  background-position: center;
}
.login .box {
  position: absolute;
  left: 50%;
  margin-left: -225px;
  top: 10%;
  width: 450px;
  padding: 40px;
  box-sizing: border-box;
  background-color: #fff;
  box-shadow: 0 3px 6px rgba(56, 65, 74, 0.1);
  border-radius: 3px;
  background-image: url("/static/images/bg-pattern-2.png");
  background-size: cover;
}
.login .box .logo {
  text-align: center;
}
.login .box .logo img {
  width: 60%;
}
.login .box .form .note {
  margin: 20px 0;
}
.login .box .form .note:first-child {
  margin-top: 0;
}
.login .box .form .input {
  margin: 20px 0;
}
.login .box .form .submit {
  width: 100%;
  margin-bottom: 20px;
  margin-top: 50px;
}
.copyright {
  position: absolute;
  bottom: 15px;
  color: #fff;
  text-align: center;
  width: 100%;
}
</style>